package com.example.thecharacterbook;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;

public class MainActivity3 extends AppCompatActivity {
    private WebView Npr;
    private ImageButton IB;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.news);
        Npr=findViewById(R.id.WebNpr);
        IB =findViewById(R.id.back);
        String strURL ="https://www.npr.org/";
        IB.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Npr.loadUrl(strURL);
                Npr.setWebViewClient(new WebViewClient(){
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view,
                                                            String url) {
                        // TODO Auto-generated method stub
                        view.loadUrl(url);//不跳到系统浏览器
                        return true;
                    }
                });
            }
        });
        //加载网页
        Npr.loadUrl(strURL);
        Npr.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view,
                                                    String url) {
                // TODO Auto-generated method stub
                view.loadUrl(url);//不跳到系统浏览器
                return true;
            }
        });
    }
}